#ifndef _VIDEO_CAP_H_
#define _VIDEO_CAP_H_
#include "gdc.h"

//input resolution
#define VIDEOCAP_TL_X	0		
#define VIDEOCAP_TL_Y	0		
#define VIDEOCAP_BR_X	680		
#define VIDEOCAP_BR_Y	500		

//input timing
#define VIDEOCAP_HCYCLE	820
#define VIDEOCAP_HSTART	122
#define VIDEOCAP_HAREA		700
#define VIDEOCAP_VSTART	25
#define VIDEOCAP_VAREA		500

//Low pass filter
#define VIDEOCAP_VLPF_LUMINANCE  2
#define VIDEOCAP_VLPF_CHROMA       2
#define VIDEOCAP_HLPF_LUMINANCE 0
#define VIDEOCAP_HLPF_CHROMA       0

//display resolution
#define VIDEOCAP_DISPWIDTH	320
#define VIDEOCAP_DISPHEIGHT	256

//Drawing Frame size
#define VIDEOCAP_DRAWWIDTH	VIDEOCAP_DISPWIDTH
#define VIDEOCAP_DRAWHEIGHT	VIDEOCAP_DISPHEIGHT

//Video settings
#define VIDEOCAP_CONTRAST	150		//MAX is 254
#define	VIDEOCAP_BRIGHTNESS	200		//MAX is 254
#define	VIDEOCAP_THRESHOLD	0x12
#define	VIDEOCAP_HDEL	0x70
#define	VIDEOCAP_RELATE	0xFF

//video misc setting
#define VIDEOCAP_MISC_ODD_MODE				GDC_CAP_EVEN_AND_ODD_MODE //GDC_CAP_ODD_ONLY_MODE
#define VIDEOCAP_MISC_CNV_MODE				GDC_CAP_CNV_BOB_MODE
#define VIDEOCAP_MISC_BURST_MODE			GDC_CAP_STANDARD_BURST_MODE
#define VIDEOCAP_MISC_RGB_CONVERT_MODE		GDC_CAP_FMT_YC
#define VIDEOCAP_MISC_BUFFER_MODE			GDC_CAP_BUF_SINGLE //GDC_CAP_BUF_RING
#define VIDEOCAP_MISC_RGB_FORMAT_MODE		GDC_CAP_ARGB
#define VIDEOCAP_MISC_RGB_BPP_FORMAT_MODE	GDC_CAP_RGB16BPP
#define VIDEOCAP_MISC_RGB_FIELD_REVERSE		GDC_DISABLE
#define VIDEOCAP_MISC_RGB565_MODE			GDC_DISABLE
//
#define VIDEOCAP_DEFAULT_CONTROLLER_INPUT	GDC_CAP_INPUT_INTERNAL

#ifdef RGB666_EN
#define VIDEOCAP_DEFAULT_INPUT_FORMAT		GDC_CAP_INPUT_RGB666 
#else
#define VIDEOCAP_DEFAULT_INPUT_FORMAT		GDC_CAP_INPUT_ITURBT656
#endif

//video capture image offset for rotation
#define VIDEOCAP_DEFAULT_VSTART_OFFSET		0x04		//For rotation
#define VIDEOCAP_DEFAULT_HSTART_OFFSET		0x05		//For rotation

enum
{
	NTSC_INPUT = 0,
	PAL_INPUT = 1,
	PALM_INPUT = 2,
	PALN_INPUT = 3
};

#define VIDEOCAP_INPUT_FMT		PAL_INPUT

enum
{
	//Video Capture input select (decoder source)
	Ext_Pin =0,
	BuiltIN_NTSC,
	DisplayOutput
};



enum
{
	//Video image format
	ITU656_mode = 0,	//Composite input
	RGB666_mode = 	1	//RGB input
};

enum
{
	//Capture buffer format
	RGB_CapBuf = 0,
	YC_CapBuf = 1
};

enum
{
	//Non-interlace mode
	BOB_mode = 0,
	WEAVE_mode	
};

enum
{
	//Video orientation
	No_Rotation=0,
	SymRotate = 1,	//y=x
	VRotate = 2,		//Vertical rotate
	HRotate = 4		//Horizontal rotate
};

typedef struct __VideoCapMisc
{
	GDC_ULONG	nOddMode;
	GDC_ULONG	nNonInterlaceMode;
	GDC_ULONG	nBurstMode;
	GDC_ULONG	nRGBConvertMode;
	GDC_ULONG	nCapBufMode;
	GDC_ULONG	nRGBFormat;
	GDC_ULONG	nRGBColorMode;
	GDC_ULONG	bFieldReversing;
	GDC_ULONG	bRGB565FormatMode;
	GDC_ULONG	nContrast;
	GDC_ULONG	nBrightness;
	GDC_ULONG	nCapInput_FMT;
}VideoCapMisc;

typedef struct __VideoCapUtil
{

	GDC_ENUM 	nCap; 			// 0 or 1
	GDC_ULONG	nCapInput; 	// 0, 1 or 2
	GDC_ULONG	nInputFormat;	// 0 or 1
	GDC_ULONG	nBufferAddr;	//video buffer start address 
	GDC_ULONG	nSrcTLX;	// 0 to input image width -1
	GDC_ULONG	nSrcTLY;	// 0 to input image height -1
	GDC_ULONG	nSrcBRX;	// 2 to input image width 
	GDC_ULONG	nSrcBRY;	// 1 to input image height
	GDC_ULONG	nCapWidth;	// 2 to 4096
	GDC_ULONG	nCapHeight;	// 1 to 4096

	unsigned char nCapRotation;
	VideoCapMisc	sMiscSetting;
}VideoCapUtil;


//General API
GDC_BOOL VideoCap_Init(VideoCapUtil* a_pVideoCapUtil, GDC_UCHAR a_nCap, GDC_ULONG a_nBufAddr);
GDC_BOOL VideoCap_Start(VideoCapUtil* a_pVideoCapUtil);
GDC_BOOL VideoCap_Stop(VideoCapUtil* a_pVideoCapUtil);
GDC_BOOL VideoCap_DeInit(VideoCapUtil* a_pVideoCapUtil);

//Configuration API
GDC_BOOL VideoCapConf_SetControllerSource(VideoCapUtil* a_pVideoCapUtil, GDC_UCHAR a_nCapInput);
GDC_BOOL VideoCapConf_SetInputFormat(VideoCapUtil* a_pVideoCapUtil, GDC_UCHAR a_nInputFormat);
GDC_BOOL VideoCapConf_SetCapBufFormat(VideoCapUtil* a_pVideoCapUtil, GDC_UCHAR a_nCapBufFormat);
GDC_BOOL VideoCapConf_SetCaptureImgArea(VideoCapUtil* a_pVideoCapUtil, GDC_ULONG a_nCapTL_X, GDC_ULONG a_nCapTL_Y, GDC_ULONG a_nCapBR_X, GDC_ULONG a_nCapBR_Y);
GDC_BOOL VideoCapConf_SetCaptureOutputArea(VideoCapUtil* a_pVideoCapUtil, GDC_ULONG a_nCapWidth, GDC_ULONG a_nCapHeight);
GDC_BOOL VideoCapConf_SetInterpolation(VideoCapUtil* a_pVideoCapUtil, GDC_ULONG a_bEnable);
GDC_BOOL VideoCapConf_SetNonInterlaceMode(VideoCapUtil* a_pVideoCapUtil, GDC_ULONG a_nInterlaceMode);
GDC_BOOL VideoCapConf_SetCapRotate(VideoCapUtil* a_pVideoCapUtil, GDC_ULONG a_nRotateMode);
void VideoCapConf_SetVStartOffset(VideoCapUtil* a_pVideoCapUtil, unsigned char a_bUseDefault, GDC_ULONG a_nValue);
void VideoCapConf_SetHStartOffset(VideoCapUtil* a_pVideoCapUtil, unsigned char a_bUseDefault, GDC_ULONG a_nValue);
void VideoCapConf_SetBrightness(VideoCapUtil* a_pVideoCapUtil, unsigned char a_bUseDefault, GDC_ULONG a_nValue);
void VideoCapConf_SetContrast(VideoCapUtil* a_pVideoCapUtil, unsigned char a_bUseDefault, GDC_ULONG a_nValue);
void VideoCapConf_SetInputFMT(VideoCapUtil* a_pVideoCapUtil, unsigned char a_bUseDefault, GDC_ULONG a_nValue);
#endif //_VIDEO_CAP_H_
